package cn.ecnu.note.mapper;

import cn.ecnu.note.pojo.Comment;
import cn.ecnu.note.vo.AdminCommentVo;
import cn.ecnu.note.vo.CommentVo;
import cn.ecnu.note.vo.ViewCommentVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CommentMapper {

    int addComment(Comment comment);

    CommentVo getCommentVoById(@Param("commentId") Integer commentId);

    @Select("SELECT COUNT(*) FROM `comment` WHERE note_id = #{noteId} AND flag = 1")
    int getCountByNoteId(@Param("noteId") Integer noteId);


    List<CommentVo> getCommentVosByNoteId(@Param("noteId") Integer noteId, @Param("startNum") Integer startNum, @Param("pageSize") Integer pageSize);

    @Select("SELECT COUNT(*) FROM `comment` WHERE user_id = #{userId} AND flag = 1")
    int getCountByUserId(@Param("userId") Integer userId);


    List<CommentVo> getCommentVosByUserId(@Param("userId") Integer userId, @Param("startNum") int pageNum, @Param("pageSize") int pageSize);

    @Select("SELECT * FROM `comment` WHERE comment_id = #{commentId} AND flag = 1")
    Comment getCommentById(@Param("commentId") Integer commentId);

    @Update("UPDATE `comment` SET flag = 0 WHERE comment_id = #{commentId}")
    int deleteCommentById(@Param("commentId") Integer commentId);


    List<AdminCommentVo> getAllComment();
}
